<template>
    <div class="wrapper-login">
       <div class="box">
           <p class="title">欢迎登录 - MMALL管理系统</p>
           <el-input class="inp" v-model="username" placeholder="请输入内容"></el-input>
           <el-input class="inp" type="password" v-model="password" placeholder="请输入内容"></el-input>
           <el-button class="btn" type="primary" @click="login">登录</el-button>
       </div>
    </div>
</template>

<script>
import { Login } from "../http/index.js";
export default {
  data() {
    return {
      username: "",
      password: ""
    };
  },
  mounted() {},
  methods: {
    login() {
      if ((this.username === "" || this.password === "")) {
        this.$message.error("请输入用户名或密码");
      } else {
        Login({ username: this.username, password: this.password }).then(
          res => {
            console.log(res);
            if (res.data.msg === "登录成功") {
              this.$message.success(res.data.msg);
              this.$router.push("/home");
            } else {
              this.$message.error("用户名或密码错误");
            }
          }
        );
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.wrapper-login {
  width: 100%;
  height: 100vh;
  background: rgb(247, 247, 247);
  position: relative;
  .box {
    width: 620px;
    height: 210px;
    border: 1px solid #ccc;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    padding: 20px;
    background: white;
    .title {
      font-family: inherit;
      font-weight: 500;
      line-height: 1.1;
    }
    .inp {
      margin-top: 15px;
    }
    .btn {
      margin-top: 20px;
      width: 100%;
      height: 30px;
      line-height: 30px;
      padding-top: 0;
    }
  }
}
</style>